// pages/me/me.js

const app = getApp();

import http from "../../utils/http.js";


Page({

  /**
   * 页面的初始数据
   */
  data: {
    islogin:null,
    menu: [{
      icon: "/images/group_12/per_info@2x.png",
      text: "账户中心",
      url: "/pages/me/account/account"
    },
    {
      icon: "/images/group_12/per_record@2x.png",
      text: "密码修改",
      url: "/pages/me/updatepwd/updatepwd"
    },
    // {
    //   icon: "/images/group_12/per_service@2x.png",
    //   text: "人工服务",
    //   url: "/pages/reserveOrder/reserveOrder?role=0"
    // },
    // {
    //   icon: "/images/group_12/per_ser_center@2x.png",
    //   text: "服务中心",
    //   url: "/pages/serviceCenter/serviceCenter"
    // },
    // {
    //   icon: "/images/group_12/per_message@2x.png",
    //   text: "我的消息",
    //   url: "/pages/myMessage/myMessage"
    // },
    ],
    sign: false,
    hidesign: true,
    userinfo: "",
    wxUser:"",
    person: "",
    family: "",
    company: "",
    role: 1, //角色权限  1管理员
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


   
  },

  getPersonalInfo() {
    let that = this;
    app.getPersonalInfo().then(function (res) {
      if (res.code == 1) {
        that.setData({
          no_see_reserve: res.data.no_see_reserve,
          userinfo: res.data.user,
          islogin: true
        })
        if (res.data.share_account_price) {
          let list = res.data.share_account_price;
          for (let i in list) {
            if (list[i].type == 1) {
              that.setData({
                family: list[i]
              })
            } else if (list[i].type == 2) {
              that.setData({
                company: list[i]
              })
            } else if (list[i].type == 3) {
              that.setData({
                person: list[i]
              })
            }
          }
        }
      }
    })
  },
  window() {
    if (!this.data.islogin) {
      wx.showToast({
        title: '请先进行登录',
        icon: "none",
        duration: 2000
      })
    }
  },
  gologin() {
    wx.navigateTo({
      url: '/pages/me/login/login',
    })
  },
  btnLogout: function (e) {
    let that= this;
    wx.showModal({
      content: '是否确定注销？',
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
        
          that.setData({
            islogin: null
          })
          // wx.removeStorage({ key: 'sessionid' });
          //取消绑定
          http.request({
            url: '/common/unbindWxId',
            success: (data) => {
              wx.removeStorage({
                key: 'userInfo',
                complete(res) {
                  console.log(res)
                }
              });
              wx.removeStorage({
                key: 'sessionid',
                complete(res) {
                  console.log(res)
                }
              });
              wx.switchTab({
                url: '/pages/index/index',
                success: res => {
                  var page = getCurrentPages().pop();
                  page.getNotice();
                }
              });
            }
          });
        }
      }
    });
  }
,

  
 

  gomenu(e) {
    console.log(this.data.islogin)
    if (this.data.islogin) {
      wx.navigateTo({
        url: e.currentTarget.dataset.url,
      })
    }
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('onshow')
    let that = this;
    wx.getStorage({
      key: 'userInfo',
      success(res) {
        if (res.data) {
          that.setData({
            userinfo: res.data,
            islogin: true
          })
        }
      },
      fail(res) {
        that.setData({
          userinfo: null,
          islogin: false
        })
      }
    })

   
    that.setData({
      //获取微信账号信息用于显示头像
      wxUser: wx.getStorageSync('wxUser')  
    })

  },

})







// Page({

//   /**
//    * 页面的初始数据
//    */
//   data: {
//     hasUserInfo: false,
//     canIUse: wx.canIUse('button.open-type.getUserInfo')
//   },

//   /**
//    * 生命周期函数--监听页面加载
//    */
//   onLoad: function(options) {
//     if (app.globalData.userInfo) {
//       this.setData({
//         userInfo: app.globalData.userInfo,
//         hasUserInfo: true
//       })
//     }
//   },
//   getUserInfo: function(e) {
//     app.globalData.userInfo = e.detail.userInfo
//     this.setData({
//       userInfo: e.detail.userInfo,
//       hasUserInfo: true
//     })
//   },
//   logout: function(e) {
//     wx.showModal({
//       content: '是否确定注销？',
//       showCancel: true,
//       success: function(res) {
//         if (res.confirm) {
//           //取消绑定
//           http.request({
//             url: '/common/unbindWxId',
//             success: (data) => {
//               wx.reLaunch({
//                 url: '../index/index'
//               });
//             }
//           });
//         }
//       }
//     });
//   }
// })